package PTA.YiChang.ex04;

import java.util.Scanner;

public class ex04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }
        ArrayUtil a=  new ArrayUtil();
        int m = sc.nextInt();
        for(int i=0;i<m;i++){
            int begin = sc.nextInt();
            int end = sc.nextInt();
            a.finMax(arr,begin,end);
        }
    }
}
class ArrayUtil{
    public void finMax(int arr[],int begin,int end){
        if(begin>=end){
            System.out.println("java.lang.IllegalArgumentException: begin:"+begin+" >= end:"+end);
        }else if(begin<0){
            System.out.println("java.lang.IllegalArgumentException: begin:"+begin+" < 0");
        }else if(end>arr.length){
            System.out.println("java.lang.IllegalArgumentException: end:"+end+" > arr.length");
        }else {
            int max = 0;
            for (int i = begin; i < end; i++) {
                if (arr[i] > max) {
                    max = arr[i];
                }
            }
            System.out.println(max);
        }
    }
}
